
<!DOCTYPE html>
<html lang="">


<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
  <meta name="theme-color" content="#202020">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  <script src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" async></script>
  
  
    <meta name="keywords" content="Javascript,">
  

  
    <meta name="description" content="Javascript Object 常用方法大全">
  
  
  <link rel="icon" type="image/x-icon" href="/logo.png">
  <title>Javascript Object 常用方法大全 [ 复制粘贴工程师 ]</title>
  
    <!-- stylesheets list from config.yml -->
    
      <link rel="stylesheet" href="//cdn.bootcss.com/pure/1.0.0/pure-min.css">
    
      <link rel="stylesheet" href="/css/xoxo.css">
    
  
</head>


<body>
  <div class="nav-container">
    <nav class="home-menu pure-menu pure-menu-horizontal">
  <a class="pure-menu-heading" href="/">
    <img class="avatar" src="https://wx.qlogo.cn/mmopen/vi_32/AMpRacDgkTPogKk4gQ5IC3QezP55XoPpicQpnD9Vz3eNz6OPFYyFrFzCa4EGQGH65kPia5YJwQBBvvJpVwQ4lfVg/132">
    <span class="title">复制粘贴工程师</span>
  </a>

  <ul class="pure-menu-list clearfix">
      
          
            <li class="pure-menu-item"><a href="/" class="pure-menu-link">首页</a></li>
          
      
          
            <li class="pure-menu-item"><a href="/search" class="pure-menu-link">搜索</a></li>
          
      
  </ul>

</nav>
  </div>

  <div class="container" id="content-outer">
    <div class="inner" id="content-inner">
      <div class="post-container">
  <article class="post" id="post">
    <header class="post-header text-center">
      <h1 class="title">
        Javascript Object 常用方法大全
      </h1>
      <span>
        
        <time class="time" datetime="2019-03-15T01:58:27.000Z">
        2019-03-15
      </time>
        
      </span>
      <span class="slash">/</span>
      <span class="post-meta">
      <span class="post-tags">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Javascript/">Javascript</a></li></ul>
      </span>
    </span>
      <span class="slash">/</span>
      <span class="read">
      <span id="busuanzi_value_page_pv"></span> 点击
    </span>
      <span class="slash">/</span>
    </header>

    <div class="post-content">
      <h4 id="Object-assign-将所有可枚举属性的值从一个或多个对象复制到目标对象，并返回目标对象"><a href="#Object-assign-将所有可枚举属性的值从一个或多个对象复制到目标对象，并返回目标对象" class="headerlink" title="Object.assign: 将所有可枚举属性的值从一个或多个对象复制到目标对象，并返回目标对象"></a>Object.assign: 将所有可枚举属性的值从一个或多个对象复制到目标对象，并返回目标对象</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj1 = &#123; <span class="attr">a</span>: <span class="number">1</span>, <span class="attr">b</span>: <span class="number">3</span>&#125;</span><br><span class="line"><span class="keyword">const</span> obj2 = &#123; <span class="attr">a</span>: <span class="number">5</span>, <span class="attr">c</span>: <span class="number">6</span>&#125;</span><br><span class="line"><span class="keyword">const</span> obj3 = <span class="built_in">Object</span>.assign(obj1, obj2)</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(obj1) <span class="comment">// &#123; a: 5, b: 3, c: 6&#125;</span></span><br><span class="line"><span class="built_in">console</span>.log(obj2) <span class="comment">// &#123; a: 5, c: 6&#125;</span></span><br><span class="line"><span class="built_in">console</span>.log(obj3) <span class="comment">// &#123; a: 5, b: 3, c: 6&#125;</span></span><br></pre></td></tr></table></figure>
<a id="more"></a>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj1 = &#123; <span class="attr">a</span>: <span class="number">1</span>, <span class="attr">b</span>: <span class="number">3</span>&#125;</span><br><span class="line"><span class="keyword">const</span> obj2 = &#123; <span class="attr">a</span>: <span class="number">5</span>, <span class="attr">c</span>: <span class="number">6</span>&#125;</span><br><span class="line"><span class="keyword">const</span> obj3 = <span class="built_in">Object</span>.assign(&#123;&#125;, obj1, obj2)</span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(obj1) <span class="comment">// &#123; a: 1, b: 3&#125;</span></span><br><span class="line"><span class="built_in">console</span>.log(obj2) <span class="comment">// &#123; a: 5, c: 6&#125;</span></span><br><span class="line"><span class="built_in">console</span>.log(obj3) <span class="comment">// &#123; a: 5, b: 3, c: 6&#125;</span></span><br></pre></td></tr></table></figure>
<h4 id="Object-defineProperty-定义或修改一个对象中的属性"><a href="#Object-defineProperty-定义或修改一个对象中的属性" class="headerlink" title="Object.defineProperty: 定义或修改一个对象中的属性"></a>Object.defineProperty: 定义或修改一个对象中的属性</h4><h4 id="Object-defineProperties-定义或修改一个对象中的多个属性"><a href="#Object-defineProperties-定义或修改一个对象中的多个属性" class="headerlink" title="Object.defineProperties: 定义或修改一个对象中的多个属性"></a>Object.defineProperties: 定义或修改一个对象中的多个属性</h4><h4 id="Object-getOwnPropertyDescriptor-获取一个对象中的一个属性描述"><a href="#Object-getOwnPropertyDescriptor-获取一个对象中的一个属性描述" class="headerlink" title="Object.getOwnPropertyDescriptor: 获取一个对象中的一个属性描述"></a>Object.getOwnPropertyDescriptor: 获取一个对象中的一个属性描述</h4><h4 id="Object-getOwnPropertyDescriptors-获取一个对象中的所有属性描述"><a href="#Object-getOwnPropertyDescriptors-获取一个对象中的所有属性描述" class="headerlink" title="Object.getOwnPropertyDescriptors: 获取一个对象中的所有属性描述"></a>Object.getOwnPropertyDescriptors: 获取一个对象中的所有属性描述</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * 数据属性</span></span><br><span class="line"><span class="comment"> * [[Configurable]]: 能否通过delete删除此属性，能否修改属性的特征</span></span><br><span class="line"><span class="comment"> * [[Enumerable]]: 该属性是否可枚举，即是否可通过for-in或Object.keys()返回属性</span></span><br><span class="line"><span class="comment"> * [[Writable]]: 能否修改属性的值</span></span><br><span class="line"><span class="comment"> * [[Value]]: 该属性的值，默认为undefined</span></span><br><span class="line"><span class="comment"> *</span></span><br><span class="line"><span class="comment"> * 访问器属性</span></span><br><span class="line"><span class="comment"> * [[Configurable]]、[[Enumerable]] 和数据属性一致</span></span><br><span class="line"><span class="comment"> * [[Get]]: 提供一个 getter 方法，访问对象属性时会调用该方法</span></span><br><span class="line"><span class="comment"> * [[Set]]: 提供一个 setter 方法，读取对象属性时会调用该方法</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// defineProperty</span></span><br><span class="line"><span class="keyword">const</span> obj = <span class="keyword">new</span> <span class="built_in">Object</span>()</span><br><span class="line"><span class="built_in">Object</span>.defineProperty(obj, <span class="string">'name'</span>, &#123;</span><br><span class="line">  configurable: <span class="literal">false</span>,</span><br><span class="line">  writable: <span class="literal">false</span>,</span><br><span class="line">  enumerable: <span class="literal">true</span>,</span><br><span class="line">  value: <span class="string">'一个不能被修改的名字'</span></span><br><span class="line">&#125;)</span><br><span class="line"><span class="built_in">console</span>.log(obj.name) <span class="comment">// '一个不能被修改的名字'</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// defineProperties</span></span><br><span class="line"><span class="keyword">const</span> obj2 = <span class="keyword">new</span> <span class="built_in">Object</span>()</span><br><span class="line"><span class="built_in">Object</span>.defineProperties(obj2, &#123;</span><br><span class="line">  name: &#123;</span><br><span class="line">    writable: <span class="literal">true</span>,</span><br><span class="line">    value: <span class="string">'张三'</span></span><br><span class="line">  &#125;,</span><br><span class="line">  Name: &#123;</span><br><span class="line">    <span class="keyword">get</span>: function() &#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="string">`<span class="subst">$&#123;<span class="keyword">this</span>.name&#125;</span>先生`</span></span><br><span class="line">    &#125;,</span><br><span class="line">    <span class="keyword">set</span>: function(value) &#123;</span><br><span class="line">      <span class="keyword">this</span>.name = value || <span class="string">'未知'</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;)</span><br><span class="line"><span class="built_in">console</span>.log(obj2.name)  <span class="comment">// 张三</span></span><br><span class="line"><span class="built_in">console</span>.log(obj2.Name)  <span class="comment">// 张三先生</span></span><br><span class="line">obj2.Name = <span class="string">''</span></span><br><span class="line"><span class="built_in">console</span>.log(obj2.name)  <span class="comment">// 未知</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// getOwnPropertyDescriptor</span></span><br><span class="line"><span class="built_in">Object</span>.getOwnPropertyDescriptor(obj2, <span class="string">'name'</span>)  <span class="comment">// ...</span></span><br><span class="line"><span class="built_in">Object</span>.getOwnPropertyDescriptor(obj2)  <span class="comment">// ...</span></span><br></pre></td></tr></table></figure>
<h4 id="Object-entries-返回一个对象自身可枚举属性的键值对，顺序与for-in循环时的顺序一致"><a href="#Object-entries-返回一个对象自身可枚举属性的键值对，顺序与for-in循环时的顺序一致" class="headerlink" title="Object.entries: 返回一个对象自身可枚举属性的键值对，顺序与for-in循环时的顺序一致"></a>Object.entries: 返回一个对象自身可枚举属性的键值对，顺序与for-in循环时的顺序一致</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = &#123; <span class="attr">foo</span>: <span class="string">'bar'</span>, <span class="attr">baz</span>: <span class="number">42</span> &#125;</span><br><span class="line"><span class="built_in">Object</span>.entries(obj) <span class="comment">// [["foo", "bar"],["baz", 42]]</span></span><br></pre></td></tr></table></figure>
<h4 id="Object-freeze-冻结一个对象-只有一层-，不能修改任何信息，包括新增属性、删除属性、修改属性值"><a href="#Object-freeze-冻结一个对象-只有一层-，不能修改任何信息，包括新增属性、删除属性、修改属性值" class="headerlink" title="Object.freeze: 冻结一个对象(只有一层)，不能修改任何信息，包括新增属性、删除属性、修改属性值"></a>Object.freeze: 冻结一个对象(只有一层)，不能修改任何信息，包括新增属性、删除属性、修改属性值</h4><h4 id="Object-isFrozen-判断一个对象是否已经被冻结"><a href="#Object-isFrozen-判断一个对象是否已经被冻结" class="headerlink" title="Object.isFrozen: 判断一个对象是否已经被冻结"></a>Object.isFrozen: 判断一个对象是否已经被冻结</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = &#123;</span><br><span class="line">  a: <span class="number">1</span>,</span><br><span class="line">  b: &#123;</span><br><span class="line">    c: <span class="number">2</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(obj.a)    <span class="comment">// 1</span></span><br><span class="line"><span class="built_in">console</span>.log(obj.b.c)  <span class="comment">// 2</span></span><br><span class="line"></span><br><span class="line">obj.a = <span class="number">3</span></span><br><span class="line">obj.b.c = <span class="number">4</span></span><br><span class="line"><span class="built_in">console</span>.log(obj.a)    <span class="comment">// 3</span></span><br><span class="line"><span class="built_in">console</span>.log(obj.b.c)  <span class="comment">// 4</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">Object</span>.isFrozen(obj)  <span class="comment">// false</span></span><br><span class="line"><span class="built_in">Object</span>.freeze(obj)</span><br><span class="line"><span class="built_in">Object</span>.isFrozen(obj)  <span class="comment">// true</span></span><br><span class="line">obj.a = <span class="number">5</span></span><br><span class="line">obj.b.c = <span class="number">6</span></span><br><span class="line"><span class="built_in">console</span>.log(obj.a)    <span class="comment">// 3</span></span><br><span class="line"><span class="built_in">console</span>.log(obj.b.c)  <span class="comment">// 6</span></span><br></pre></td></tr></table></figure>
<h4 id="Object-keys-获取一个对象中所有的key值-不包括不可枚举属性和Symbol属性"><a href="#Object-keys-获取一个对象中所有的key值-不包括不可枚举属性和Symbol属性" class="headerlink" title="Object.keys: 获取一个对象中所有的key值(不包括不可枚举属性和Symbol属性)"></a>Object.keys: 获取一个对象中所有的key值(不包括不可枚举属性和Symbol属性)</h4><h4 id="Object-values-获取一个对象中所有的value值（不包括不可枚举属性和Symbol属性）"><a href="#Object-values-获取一个对象中所有的value值（不包括不可枚举属性和Symbol属性）" class="headerlink" title="Object.values: 获取一个对象中所有的value值（不包括不可枚举属性和Symbol属性）"></a>Object.values: 获取一个对象中所有的value值（不包括不可枚举属性和Symbol属性）</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = &#123;&#125;</span><br><span class="line"><span class="built_in">Object</span>.defineProperty(obj, <span class="string">'a'</span>, &#123;<span class="attr">Enumerable</span>: <span class="literal">false</span>, <span class="attr">value</span>: <span class="number">1</span>&#125;)</span><br><span class="line">obj[<span class="built_in">Symbol</span>()] = <span class="number">2</span></span><br><span class="line">obj[<span class="string">'b'</span>] = <span class="number">3</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Object</span>.keys(obj)) <span class="comment">// ['b']</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Object</span>.values(obj)) <span class="comment">// ['3']</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Object</span>.getOwnPropertyNames(obj)) <span class="comment">// ['a', 'b']</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Object</span>.getOwnPropertySymbols(obj)) <span class="comment">// [Symbol()]</span></span><br></pre></td></tr></table></figure>
<h4 id="Object-getOwnPropertyNames-获取一个对象所有属性的key值-包括不可枚举属性，不包括Symbol属性"><a href="#Object-getOwnPropertyNames-获取一个对象所有属性的key值-包括不可枚举属性，不包括Symbol属性" class="headerlink" title="Object.getOwnPropertyNames: 获取一个对象所有属性的key值(包括不可枚举属性，不包括Symbol属性)"></a>Object.getOwnPropertyNames: 获取一个对象所有属性的key值(包括不可枚举属性，不包括Symbol属性)</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = &#123;</span><br><span class="line">  foo: <span class="string">'bar'</span>,</span><br><span class="line">  baz: <span class="number">43</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">Object</span>.getOwnPropertyNames(obj) <span class="comment">// ['foo', 'baz']</span></span><br></pre></td></tr></table></figure>
<h4 id="Object-getOwnPropertySymbols-获取一个对象所有Symbol属性"><a href="#Object-getOwnPropertySymbols-获取一个对象所有Symbol属性" class="headerlink" title="Object.getOwnPropertySymbols: 获取一个对象所有Symbol属性"></a>Object.getOwnPropertySymbols: 获取一个对象所有Symbol属性</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = &#123;&#125;</span><br><span class="line">obj[<span class="built_in">Symbol</span>(<span class="string">'a'</span>)] = <span class="string">'localSymbol'</span></span><br><span class="line">obj[<span class="built_in">Symbol</span>.for(<span class="string">'b'</span>)] = <span class="string">'globalSymbol'</span></span><br><span class="line"><span class="built_in">Object</span>.getOwnPropertySymbols(obj) <span class="comment">// [Symbol(a), Symbol(b)]</span></span><br></pre></td></tr></table></figure>
<h4 id="拓展：Symbol是为了保证对象属性的一致性"><a href="#拓展：Symbol是为了保证对象属性的一致性" class="headerlink" title="拓展：Symbol是为了保证对象属性的一致性"></a>拓展：Symbol是为了保证对象属性的一致性</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> sy = <span class="built_in">Symbol</span>(<span class="string">'a'</span>)</span><br><span class="line"><span class="keyword">const</span> obj = &#123;&#125;</span><br><span class="line">obj[<span class="built_in">Symbol</span>(<span class="string">'a'</span>)] = <span class="number">3</span>  <span class="comment">// &#123;Symbol(a): 3&#125;</span></span><br><span class="line">obj[sy] = <span class="number">4</span>  <span class="comment">// &#123;Symbol(a): 3, Symbol(a): 4&#125;</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(obj[<span class="built_in">Symbol</span>(<span class="string">'a'</span>)]) <span class="comment">// undefined</span></span><br><span class="line"><span class="built_in">console</span>.log(obj[sy])  <span class="comment">// 4</span></span><br></pre></td></tr></table></figure>
<h4 id="Object-preventExtensions-使一个对象不再具有拓展性（不能添加新属性）"><a href="#Object-preventExtensions-使一个对象不再具有拓展性（不能添加新属性）" class="headerlink" title="Object.preventExtensions: 使一个对象不再具有拓展性（不能添加新属性）"></a>Object.preventExtensions: 使一个对象不再具有拓展性（不能添加新属性）</h4><h4 id="Object-isExtensible-判断一个对象是否具有拓展性"><a href="#Object-isExtensible-判断一个对象是否具有拓展性" class="headerlink" title="Object.isExtensible: 判断一个对象是否具有拓展性"></a>Object.isExtensible: 判断一个对象是否具有拓展性</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = &#123;<span class="attr">v1</span>: <span class="number">1</span>&#125; <span class="comment">// &#123;v1:1&#125;</span></span><br><span class="line">obj.v2 = <span class="number">2</span>  <span class="comment">// &#123;v1:1, v2:2&#125;</span></span><br><span class="line"><span class="built_in">Object</span>.preventExtensions(obj)</span><br><span class="line">obj.v3 = <span class="number">3</span>  <span class="comment">// &#123;v1:1, v2:2&#125;</span></span><br><span class="line">obj.v2 = <span class="number">3</span>  <span class="comment">// &#123;v1:1, v2:3&#125;</span></span><br><span class="line"><span class="built_in">Object</span>.isExtensible(obj)  <span class="comment">// false</span></span><br></pre></td></tr></table></figure>
<h4 id="hasOwnProperty-判断一个对象是否包含某个属性-不包括原型链上的属性"><a href="#hasOwnProperty-判断一个对象是否包含某个属性-不包括原型链上的属性" class="headerlink" title="hasOwnProperty: 判断一个对象是否包含某个属性(不包括原型链上的属性)"></a>hasOwnProperty: 判断一个对象是否包含某个属性(不包括原型链上的属性)</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> obj = &#123; <span class="attr">a</span>: <span class="number">2</span> &#125;</span><br><span class="line">obj.hasOwnProperty(<span class="string">'a'</span>) <span class="comment">// true</span></span><br><span class="line">obj.hasOwnProperty(<span class="string">'b'</span>) <span class="comment">//false</span></span><br></pre></td></tr></table></figure>
<h4 id="isPrototypeOf-判断一个对象是否在某个对象的原型链上"><a href="#isPrototypeOf-判断一个对象是否在某个对象的原型链上" class="headerlink" title="isPrototypeOf: 判断一个对象是否在某个对象的原型链上"></a>isPrototypeOf: 判断一个对象是否在某个对象的原型链上</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fn</span>(<span class="params"></span>) </span>&#123;&#125;</span><br><span class="line">_fn1 = <span class="keyword">new</span> fn() <span class="comment">// fn &#123;&#125;</span></span><br><span class="line">_fn2 = fn()     <span class="comment">// undefined</span></span><br><span class="line"><span class="built_in">console</span>.log(fn.isPrototypeOf(_fn1)) <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(fn.prototype.isPrototypeOf(_fn1)) <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(fn.prototype.isPrototypeOf(_fn2)) <span class="comment">// false</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Object</span>.prototype.isPrototypeOf(_fn1)) <span class="comment">// true</span></span><br><span class="line"><span class="built_in">console</span>.log(<span class="built_in">Object</span>.prototype.isPrototypeOf(_fn2)) <span class="comment">// false</span></span><br></pre></td></tr></table></figure>

    </div>

    <div>全文完。</div>
  </article>
  <div class="toc-container">
    
  <div id="toc" class="toc-article">
    <strong class="toc-title">目录</strong>
    <ol class="toc"><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-assign-将所有可枚举属性的值从一个或多个对象复制到目标对象，并返回目标对象"><span class="toc-text">Object.assign: 将所有可枚举属性的值从一个或多个对象复制到目标对象，并返回目标对象</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-defineProperty-定义或修改一个对象中的属性"><span class="toc-text">Object.defineProperty: 定义或修改一个对象中的属性</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-defineProperties-定义或修改一个对象中的多个属性"><span class="toc-text">Object.defineProperties: 定义或修改一个对象中的多个属性</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-getOwnPropertyDescriptor-获取一个对象中的一个属性描述"><span class="toc-text">Object.getOwnPropertyDescriptor: 获取一个对象中的一个属性描述</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-getOwnPropertyDescriptors-获取一个对象中的所有属性描述"><span class="toc-text">Object.getOwnPropertyDescriptors: 获取一个对象中的所有属性描述</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-entries-返回一个对象自身可枚举属性的键值对，顺序与for-in循环时的顺序一致"><span class="toc-text">Object.entries: 返回一个对象自身可枚举属性的键值对，顺序与for-in循环时的顺序一致</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-freeze-冻结一个对象-只有一层-，不能修改任何信息，包括新增属性、删除属性、修改属性值"><span class="toc-text">Object.freeze: 冻结一个对象(只有一层)，不能修改任何信息，包括新增属性、删除属性、修改属性值</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-isFrozen-判断一个对象是否已经被冻结"><span class="toc-text">Object.isFrozen: 判断一个对象是否已经被冻结</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-keys-获取一个对象中所有的key值-不包括不可枚举属性和Symbol属性"><span class="toc-text">Object.keys: 获取一个对象中所有的key值(不包括不可枚举属性和Symbol属性)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-values-获取一个对象中所有的value值（不包括不可枚举属性和Symbol属性）"><span class="toc-text">Object.values: 获取一个对象中所有的value值（不包括不可枚举属性和Symbol属性）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-getOwnPropertyNames-获取一个对象所有属性的key值-包括不可枚举属性，不包括Symbol属性"><span class="toc-text">Object.getOwnPropertyNames: 获取一个对象所有属性的key值(包括不可枚举属性，不包括Symbol属性)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-getOwnPropertySymbols-获取一个对象所有Symbol属性"><span class="toc-text">Object.getOwnPropertySymbols: 获取一个对象所有Symbol属性</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#拓展：Symbol是为了保证对象属性的一致性"><span class="toc-text">拓展：Symbol是为了保证对象属性的一致性</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-preventExtensions-使一个对象不再具有拓展性（不能添加新属性）"><span class="toc-text">Object.preventExtensions: 使一个对象不再具有拓展性（不能添加新属性）</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Object-isExtensible-判断一个对象是否具有拓展性"><span class="toc-text">Object.isExtensible: 判断一个对象是否具有拓展性</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#hasOwnProperty-判断一个对象是否包含某个属性-不包括原型链上的属性"><span class="toc-text">hasOwnProperty: 判断一个对象是否包含某个属性(不包括原型链上的属性)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#isPrototypeOf-判断一个对象是否在某个对象的原型链上"><span class="toc-text">isPrototypeOf: 判断一个对象是否在某个对象的原型链上</span></a></li></ol>
  </div>


  </div>
</div>
<div class="copyright">
    <span>本作品采用</span>
    <a href="https://creativecommons.org/licenses/by/4.0/">知识共享署名 4.0 国际许可协议</a>
    <span>进行许可。 转载时请注明原文链接。</span>
</div>
<div class="share" style="width: 100%;">
  <!-- <img src="https://kevinofneu-blog-static.oss-cn-beijing.aliyuncs.com/static/2018-12-10-qrcode_for_gh_ffacf5722095_258.jpg" alt="Running Geek" style="margin: auto; display: block;"/>

  <div style="margin: auto; text-align: center; font-size: 0.8em; color: grey;">老铁们关注走一走，不迷路</div> -->

</div>

  
    <div class="post-nav">
      <div class="post-nav-item post-nav-next">
        
          <span>〈 </span>
          <a href="/2019/03/14/Javascript数组方法大全/" rel="next" title="Javascript数组方法大全">
          Javascript数组方法大全
          </a>
        
      </div>
  
      <div class="post-nav-item post-nav-prev">
          
          <a href="/2019/03/19/Resultful风格接口/" rel="prev" title="Resultful风格接口">
            Resultful风格接口
          </a>
          <span>〉</span>
        
      </div>
    </div>
  


    </div>

    
    <div id="vcomments" style="max-width: 800px; margin: 16px auto;"></div>
  </div>
  <footer class="footer text-center">
    <div id="bottom-inner">
        <a class="bottom-item" href="/">首页</a> |
        <a class="bottom-item" href="https://github.com/TJ-XiaJiaHao" target="_blank">GitHub</a> |
        <a class="bottom-item">联系邮箱：1452806@tongji.edu.cn</a>
    </div>
</footer>
  

<script>
  (function(window, document, undefined) {

    var timer = null;

    function returnTop() {
      cancelAnimationFrame(timer);
      timer = requestAnimationFrame(function fn() {
        var oTop = document.body.scrollTop || document.documentElement.scrollTop;
        if (oTop > 0) {
          document.body.scrollTop = document.documentElement.scrollTop = oTop - 50;
          timer = requestAnimationFrame(fn);
        } else {
          cancelAnimationFrame(timer);
        }
      });
    }

    var hearts = [];
    window.requestAnimationFrame = (function() {
      return window.requestAnimationFrame ||
        window.webkitRequestAnimationFrame ||
        window.mozRequestAnimationFrame ||
        window.oRequestAnimationFrame ||
        window.msRequestAnimationFrame ||
        function(callback) {
          setTimeout(callback, 1000 / 60);
        }
    })();
    init();

    function init() {
      css(".heart{z-index:9999;width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: absolute;}.heart:after{top: -5px;}.heart:before{left: -5px;}");
      attachEvent();
      gameloop();
      addMenuEvent();
    }

    function gameloop() {
      for (var i = 0; i < hearts.length; i++) {
        if (hearts[i].alpha <= 0) {
          document.body.removeChild(hearts[i].el);
          hearts.splice(i, 1);
          continue;
        }
        hearts[i].y--;
        hearts[i].scale += 0.004;
        hearts[i].alpha -= 0.013;
        hearts[i].el.style.cssText = "left:" + hearts[i].x + "px;top:" + hearts[i].y + "px;opacity:" + hearts[i].alpha + ";transform:scale(" + hearts[i].scale + "," + hearts[i].scale + ") rotate(45deg);background:" + hearts[i].color;
      }
      requestAnimationFrame(gameloop);
    }

    /**
     * 给logo设置点击事件
     * 
     * - 回到顶部
     * - 出现爱心
     */
    function attachEvent() {
      var old = typeof window.onclick === "function" && window.onclick;
      var logo = document.getElementById("logo");
      if (logo) {
        logo.onclick = function(event) {
          returnTop();
          old && old();
          createHeart(event);
        }
      }
      
    }

    function createHeart(event) {
      var d = document.createElement("div");
      d.className = "heart";
      hearts.push({
        el: d,
        x: event.clientX - 5,
        y: event.clientY - 5,
        scale: 1,
        alpha: 1,
        color: randomColor()
      });
      document.body.appendChild(d);
    }

    function css(css) {
      var style = document.createElement("style");
      style.type = "text/css";
      try {
        style.appendChild(document.createTextNode(css));
      } catch (ex) {
        style.styleSheet.cssText = css;
      }
      document.getElementsByTagName('head')[0].appendChild(style);
    }

    function randomColor() {
      // return "rgb(" + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + "," + (~~(Math.random() * 255)) + ")";
      return "#F44336";
    }

    function addMenuEvent() {
      var menu = document.getElementById('menu-main-post');
      if (menu) {
        var toc = document.getElementById('toc');
        if (toc) {
          menu.onclick = function() {
            if (toc) {
              if (toc.style.display == 'block') {
                toc.style.display = 'none';
              } else {
                toc.style.display = 'block';
              }
            }
          };
        } else {
          menu.style.display = 'none';
        }
      }
    }

  })(window, document);
</script>

  



</body>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src='//unpkg.com/valine/dist/Valine.min.js'></script>
<script type="text/javascript">
  new Valine({
    el: '#vcomments',
    appId: '8CwYqXS8IoFbvaA9PmgqGjTf-gzGzoHsz',
    appKey: 'z5bVoSPDPhd8hzlXvDey5Hpz',
    verify:false,
    placeholder: '评论留言'
  })
</script>
</html>
